import React, { Component } from 'react'
import {ListBox} from '../../../components'
import {fetchData} from '../../../components/AjaxConsumer'
import {  Button, Modal, Form, Input, Radio,Upload, Icon } from 'antd';
export default class ListProScrapOutOrderPage extends Component {
    constructor(props) {
        super(props);
        this.state = {
            tableColumn: {},
            searchComponentData: [],
            visible: false,
        };
        //行操作列表
        this.rowOperation = [
        ];
        //header 操作列表
        this.headerOperation = [
        ];

        //table列表展示列配置
        //showName、columnName 必有属性， columnWidth 可选，默认100, columnHidden: true 列隐藏
        this.tableColumn = {
            storageKey: 'scrapOutOrderId',
            data: [
                // { 
                //     showName: '班组',
                //     columnName: 'userDefined1',
                //     showOption:[
                //         {
                //             optionKey:'',
                //             optionShow:''
                //         }, {
                //             optionKey:'1',
                //             optionShow:'甲班'
                //         }, {
                //             optionKey:'2',
                //             optionShow:'乙班'
                //         }, {
                //             optionKey:'3',
                //             optionShow:'丙班'
                //         }
                //     ]
                // },
                {
                    showName: '日期',
                    columnName: 'gmtCreate'
                },
                {
                    showName: '仓库',
                    columnName: 'waCode',
                    showOption: []
                },
                {
                    showName: '生产机号',
                    columnName: 'machineNumber',
                    showOption: []
                },
                {
                    showName: '型号',
                    columnName: 'model'
                }, {
                    showName: '商标',
                    columnName: 'productName'
                }, {
                    showName: '定量',
                    columnName: 'density'
                }, {
                    showName: '规格',
                    columnName: 'spec'
                }, {
                    showName: '等级',
                    columnName: 'grade',
                    showOption:[
                        {
                            optionKey:'',
                            optionShow:''
                        }, {
                            optionKey:'1',
                            optionShow:'一等品'
                        }, {
                            optionKey:'2',
                            optionShow:'二等品'
                        }, {
                            optionKey:'3',
                            optionShow:'处理品'
                        }
                    ]
                }, {
                    showName: '件数',
                    columnName: 'codeNum'
                }, {
                    showName: '重量',
                    columnName: 'codeWt'
                },
            ]
        };

        //搜索属性配置
        this.searchComponentData = [
            {
                showName: '等级',
                name: 'grade',
                type: 'select',
                optionList:[
                    {
                        optionKey:'',
                        optionShow:''
                    },{
                        optionKey:'1',
                        optionShow:'一等品'
                    },{
                        optionKey:'2',
                        optionShow:'二等品'
                    },{
                        optionKey:'3',
                        optionShow:'处理品'
                    }
                ]
            }, {
                showName: '日期',
                name:'gmtCreate',
                type: 'date',
                maxName:'gmtCreateMax',
                minName:'gmtCreateMin'
            }, {
                showName: '生产机号',
                name: 'machineNumber',
                type: 'select',
                optionList: []
                // url:'/base/dic/get/machine_number'
            }, {
                showName: '仓库',
                name: 'waCode',
                type: 'select',
                // optionList: []
                url: '/base/data/area/get/wa_code'
            }, {
                showName: '件数',
                name: 'codeNum',
                type: 'number',
                maxName:'codeNumMax',
                minName:'codeNumMin'
            }, {
                showName: '重量',
                name: 'codeWt',
                type: 'number',
                maxName:'codeWtMax',
                minName:'codeWtMin'
            }
        ];

    }

    componentWillMount() {
        const dicType = 'machine_number';
        const options= {
            url: '/base/dic/get/' + dicType,
            type: 'get',
            condition:{}
        };
        //先写死，后面再改
        fetchData(this, options, this.dicInitCallBackHandle);

        // const teamsOptions = {
        //     url: '/base/team/getTeams',
        //     type: 'get'
        // }
        // fetchData(this, teamsOptions, this.teamsInitCallbackHandle);

        // const waCodeOptions = {
        //     url: '/base/data/area/get/wa_code',
        //     type: 'get'
        // }
        // fetchData(this, waCodeOptions, this.waCodeInitCallbackHandle);
    }

    //下拉框 初始化
    dicInitCallBackHandle = (resData)=>{
        //alert('resData' + JSON.stringify(resData, null, 4));
        let optionList = [];
        let tmp = {};
        tmp.optionKey = '';
        tmp.optionShow = '';
        optionList.push(tmp);
        resData.data.map( (e,index) => {
            let tmp = {};
            tmp.optionKey = Number(e.dicCode);
            tmp.optionShow = e.dicName;
            optionList.push(tmp);
        });

        //alert('optionList' + JSON.stringify(optionList, null, 4));
        this.tableColumn.data[2].showOption = optionList;
        this.searchComponentData[2].optionList = optionList;
    }
    // teamsInitCallbackHandle = (resData) => {
    //     let optionList = [];
    //     optionList.push('');
    //     resData.data.map((e, index) => {
    //         let tmp = {};
    //         tmp.optionKey = e.teamCode;
    //         tmp.optionShow = e.teamName;
    //         optionList.push(tmp);
    //     });
    //     this.tableColumn.data[0].showOption = optionList;
    //     this.searchComponentData[3].optionList = optionList;
    // }
    // waCodeInitCallbackHandle = (resData)=>{
    //     // alert('resData' + JSON.stringify(resData, null, 4));
    //     let optionList = [];
    //     let tmp = {};
    //     tmp.optionKey = '';tmp.optionShow = '';
    //     optionList.push(tmp);
    //     resData.data.map( (e,index) => {
    //         let tmp = {};
    //         tmp.optionKey = e.dicCode;
    //         tmp.optionShow = e.dicName;
    //         optionList.push(tmp);
    //     });
    //     //alert('optionList' + JSON.stringify(optionList, null, 4));
    //     this.tableColumn.data[2].showOption = optionList;
    //     this.searchComponentData[4].optionList = optionList;
    // }

    rowHandles = (strHandles, rowObj) => {
        // console.log("strHandles===ListResource=======", strHandles);
        // if (strHandles === 'edit') {
        //     this.editHandle(rowObj);
        // }
    }

    //刷新列表
    refreshHandle = () => {
        this.refs.listProScrapOutOrder.refreshHandle();
    }

  handleCancel = () => {
    this.setState({ visible: false });
      this.form.resetFields();
    
  }
  handleCreate = () => {
    const form = this.form;
    form.validateFields((err, values) => {
      if (err) {
        return;
      }

      console.log('Received values of form: ', values);
      form.resetFields();
      this.setState({ visible: false });
    });
  }
  saveFormRef = (form) => {
    this.form = form;
  }


    render() {
        //当左侧隐藏时，列表宽度加上左侧的宽度，
        //1、当前this.props.isHideLeft 是从页面组件containers/Main/main.js传过来
        //2、this.props.isHideLeft 最顶级赋值是在页面 containers/Main/main.js
        let isHideLeft = this.props.isHideLeft;

        return (
            <div>
                <ListBox
                    ref='listProScrapOutOrder'
                    title="成品报废出库统计"
                    isHideLeft={isHideLeft}
                    tableColumnData={this.tableColumn}
                    searchComponentData={this.searchComponentData}
                    url='/product/proscrapoutsn/outOrder'
                    rowHandles={this.rowHandles}
                    rowOperation={this.rowOperation}
                    headerOperation={this.headerOperation}
                    isRowSingle = "true"
                />
            
            </div>
        )
    }
}
